<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增电子档案')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form enctype="multipart/form-data"  class="form-horizontal m" id="form-image-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">员工姓名：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input id="treeId" name="userId" type="hidden" th:value="${user.id}" />
                        <input class="form-control" type="text" onclick="selectUserTree()" id="treeName" readonly="true" th:value="${user.name}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">档案类型：</label>
                <div class="col-sm-8">
                    <select name="imageType" class="form-control m-b" th:with="type=${@dict.getType('basic_image_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">电子档案：</label>
                <div class="col-sm-8">
                    <input accept="*/*" id="file" name="files" multiple="multiple" th:onchange="gen_size()" type="file">
                    <font color="red" class="pull-left mt10">
                        提示：选择导入的电子档案！
                    </font>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "basic/image"
        $("#form-image-add").validate({
            focusCleanup: true
        });

        /* 选择人员 */
        function selectUserTree() {
            var options = {
                title: '选择员工',
                width: "380",
                url: ctx + "basic/user/selectTree",
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            var treeType = body.find('#treeType').val();
            if(treeType == 'user'){
                var id = body.find('#treeId').val();
                var treeId = id.substring(id.indexOf('_') + 1, id.length);
                $("#treeId").val(treeId);
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }else{
                $.modal.alertError("请选择员工");
            }
        }

        function gen_size(){
            var files = document.getElementById("file").files;
            var size = 0;
            for(var i = 0; i < files.length; i++){
                var file = files[i];
                size = parseFloat(file.size) + parseFloat(size);
            }
            if(size > 200 * 1024 * 1024){
                $.modal.alertError("超出最大限制：200M");
                return;
            }
        }

        function submitHandler() {
            if ($.validate.form()) {
                var formData = new FormData($('#form-image-add')[0]);
                $.operate.saveFile(prefix + "/add", formData);
            }
        }
    </script>
</body>
</html>